package com.itsm.controller.user;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.itsm.facade.entity.user.Account;
import com.itsm.facade.service.user.IAccountService;
import com.itsm.request.RequestData;
import com.itsm.response.ResponeData;
import com.itsm.util.JwtTokenUtil;

/**
 * <p>
 * 后台账号管理 前端控制器
 * </p>
 *
 * @author 张权
 * @since 2017-09-28
 */
@Controller
@RequestMapping("/account")
public class AccountController {
	@Autowired
	private IAccountService accountService;
	@Autowired
	private JwtTokenUtil jwtTokenUtil;
	
	@RequestMapping("/toAccountList")
	public String toAccountList() {
		return "user/account/findAccountList";
	}
	
	
	@ResponseBody
	@RequestMapping("/getToken")
	public ResponeData getToken() {
		String token = jwtTokenUtil.generateToken("123", System.currentTimeMillis()+"");
		ResponeData respone = new ResponeData();
		respone.setCode("0");
		respone.setData(token);
		return respone;
	}
	/**
	 * 表格展示账号信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/selectAccountList")
	public ResponeData selectAccountList(RequestData requestData,Account account) {
		int current = requestData.getPage();
		int size = requestData.getLimit();
		Page<Account> page = new Page<>(current, size);
		page.setSearchCount(true);
		Wrapper<Account> wrapper = new EntityWrapper<>();
		wrapper.like("account_name", account.getAccountName());
		wrapper.like("nick_name", account.getNickName());
		page = accountService.selectPage(page , wrapper );
		List<Account> datas = page.getRecords();
		ResponeData respone = new ResponeData(datas);
		respone.setCount(page.getTotal());
		respone.setCode("0");
		
		
		return respone;
	}
	
	public static void main(String[] args) {
		System.out.println(StringUtils.reverse("6839511307162805113071"));
	}
	
}
